from spire.xls import *
import datetime
data = {
    "this_week_task": [
        {
            "task": "应用白名单",
            "executor": "汪炳志、陈翰",
            "plan_end_time": "2024-08-07",
            "state": "完成"
        },
        {
            "task": "AIPC-服务器版:在ubuntu系统下，基础框架的搭建及前台问答接口开发",
            "executor": "黄星",
            "plan_end_time": "2024-08-07",
            "state": "完成"
        },
        {
            "task": "鸿蒙数字签名",
            "executor": "李山川",
            "plan_end_time": "2024-08-09",
            "state": "完成"
        },
        {
            "task": "IVY Audio Device、IVY Virtual Multi HID Device移植到ARM64平台",
            "executor": "杨帆",
            "plan_end_time": "2024-08-08",
            "state": "完成"
        },
        {
            "task": "rebootAPP页面优化（改成卡片模式）",
            "executor": "陈惠",
            "plan_end_time": "2024-08-08",
            "state": "未完成",
            "next_plan_end_time": "2024-08-21"
        },
        {
            "task": "wddm显示驱动移植",
            "executor": "杨帆",
            "plan_end_time": "2024-08-09",
            "state": "未完成",
            "next_plan_end_time": "待定"
        },
        {
            "task": "移远5G模块,RM500U迁移到鸿蒙+M900",
            "executor": "游开威",
            "plan_end_time": "2024-08-09",
            "state": "未完成",
            "next_plan_end_time": "2024-08-21"
        }
    ],
    "next_week_task": [
        {
            "task": "5G模块适配和功能改进",
            "executor": "未明确指定",
            "plan_end_time": "2024-08-21",
            "state": "-"
        },
        {
            "task": "Reboot app界面优化",
            "executor": "陈惠",
            "plan_end_time": "2024-08-21",
            "state": "-"
        },
        {
            "task": "西界知识单适配问题处理",
            "executor": "未明确指定",
            "plan_end_time": "2024-08-21",
            "state": "-"
        },
        {
            "task": "速度优化研究",
            "executor": "未明确指定",
            "plan_end_time": "2024-08-23",
            "state": "-"
        },
        {
            "task": "WDDM显示驱动移植研究",
            "executor": "杨帆",
            "plan_end_time": "待定",
            "state": "-"
        },
        {
            "task": "鸿蒙双进程守护开发",
            "executor": "未明确指定",
            "plan_end_time": "2024-08-23",
            "state": "-"
        }
    ]
}
wb = Workbook()
wb.LoadFromFile("template.xlsx")

sheet = wb.Worksheets[0]

# 计算本周一和本周五的日期
# 计算本周一和本周五的日期
today = datetime.datetime.today()
weekday = today.weekday()  # 0=Monday, 6=Sunday
monday = today - datetime.timedelta(days=weekday)
friday = monday + datetime.timedelta(days=4)

# 格式化日期
monday_str = monday.strftime('%m月%d')
friday_str = friday.strftime('%m月%d')
all_friday_str = friday.strftime('%Y-%m-%d')
# 创建会议标题
meeting_title = f"{monday_str}-{friday_str}例会"

sheet.Range["B3"].Text = meeting_title
sheet.Range["B4"].Text = all_friday_str


this_week_template_row = sheet.Rows[7]
next_week_template_row = sheet.Rows[8]
first_row_index = 10
row_index = first_row_index


for task in data.get("this_week_task"):
    sheet.CopyRow(this_week_template_row, sheet, row_index, CopyRangeOptions.All)
    sheet.Range["B{}".format(row_index)].Text = "{};--{}".format(task.get("task"), task.get("state"))
    sheet.Range["F{}".format(row_index)].Text = task.get("executor")
    sheet.Range["G{}".format(row_index)].Text = task.get("plan_end_time")
    row_index += 1

if row_index - 1 > first_row_index:
    sheet.Range["A{}:A{}".format(first_row_index, row_index - 1)].Merge()

first_row_index = row_index
for task in data.get("next_week_task"):
    sheet.CopyRow(next_week_template_row, sheet, row_index, CopyRangeOptions.All)
    sheet.Range["B{}".format(row_index)].Text = task.get("task")
    sheet.Range["F{}".format(row_index)].Text = task.get("executor")
    sheet.Range["G{}".format(row_index)].Text = task.get("plan_end_time")
    row_index += 1
if row_index - 1 > first_row_index:
    sheet.Range["A{}:A{}".format(first_row_index, row_index - 1)].Merge()
sheet.DeleteRow(8, 2)

wb.SaveToFile("result.xlsx")
